package outoforder.leetcode;

import java.util.concurrent.*;

/**
 * @author shhjiang_001
 * @create 2020-06-30 13:01
 */
public class Demo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<String> stringFuture = executor.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(2000);
                return "async thread";
            }
        });
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main thread");
        System.out.println(stringFuture.get());
        // 注意此处需要关闭线程池，否则会导致程序无法运行
        executor.shutdown();
    }
}
